package top.chukongxiang.monitorservice.model.response;

import lombok.Data;

/**
 * @author 楚孔响
 * @version 1.0
 * @date 2023/11/3 13:36
 */
@Data
public class R<T> {

    private Integer code;
    private String msg;
    private T data;

    public static <E> R<E> ok(E data) {
        return result(1, "请求成功", data);
    }

    public static <E> R<E> ok() {
        return ok(null);
    }

    public static <E> R<E> failed(String msg) {
        return result(-1, msg, null);
    }

    public static <E> R<E> failed() {
        return failed("业务异常");
    }

    public static <E> R<E> result(Integer code, String msg, E data) {
        R<E> result = new R<>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
}
